#include "./SampleLevelConstructor.h"

#include <string>
#include <boost/lexical_cast.hpp>
#include <Ogre.h>
#include "../../Graphics/Presentation.h"

GameLogic::Level::Level* SampleLevelConstructor() {
	GameLogic::Level::Level* level = new GameLogic::Level::Level( 10, 10, 2.0f ); //LevelLevel level levelLevelLevelLevel level

	//konfiguruje scene:
	Ogre::SceneManager* scene_manager = Graphics::Presentation::getInstance().getSceneManager();

	scene_manager->setAmbientLight( Ogre::ColourValue( 1.0f, 0.8f, 1.0f ) );

	Ogre::Light* l = scene_manager->createLight();
	l->setPosition(10.0f, 10.0f, 20.0f);

	//Tworzy kawalek podlogi:
	Ogre::Plane plane( Ogre::Vector3( 0.5f, 0.5f, 0.5f ), 0.0f );
	//plane.normal = Ogre::Vector3::UNIT_Y;
	//plane.d = 0;
	Ogre::MeshManager::getSingleton().createPlane(
			"floor",
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			plane,
			2.0f,
			2.0f,
			2, 2, true, 0
	);

	Graphics::Presentation::createSphere("ballfloor",Graphics::Presentation::toOgreCoords( 1.0f ),10,10,"BaseWhiteLightning");

	//ustawia tile:
	for( int i = 1; i < level->getWidth() - 1; ++i ) {
		for( int j = 1; j < level->getHeight() - 1; ++j ) {
			//setup scene node
			Ogre::Entity* entity_ = scene_manager->createEntity("flr" + boost::lexical_cast< std::string >( j * level->getWidth() + i ), "ballfloor");
			Ogre::SceneNode* sn = Graphics::Presentation::getInstance().createSceneNode( entity_ );
			//dolacza tila do levelu:
			level->insertTile( i, j, new GameLogic::Level::Tile( sn ) );
		}
	}

	level->setSpawnPoint( 0 , Vec2f(4.0f,4.0f) );
	level->setSpawnPoint( 0 , Vec2f(16.0f,16.0f) );

	return level;
}
